package com.gaofeng.javase.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemo02 {
    public static void main(String[] args) {

        // 创建Map集合对象
        HashMap<String, String> map = new HashMap<>();
        map.put("1", "张三");
        map.put("2", "李四");
        map.put("3", "王五");
        System.out.println(map);

        // 遍历Map集合
        Set<String> keys = map.keySet();

        for(String key:keys){
            System.out.println(key);
            String res = map.get(key);
            System.out.println(res);
        }

        // 遍历Map集合，键值对
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for(Map.Entry<String, String> entry:entries){
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "=" + value);
        }
    }
}
